﻿#ifndef ErrLog_h__2013_7_30__16_30
#define ErrLog_h__2013_7_30__16_30

#include "df.h"


#	define DF_ERR(msg) df::LastErr(df::String()<< msg);
#	define DF_ERR2     df::LastErr(tcc_(""));


#if DF_LOG_TO_FILE==1
#	define DF_LOG(msg) df::WriteLog(df::String()<< msg);
#	define DF_ERRLOG(err,code,msg) do{	\
	df::String ss; \
	ss << msg; \
	df::WriteLog(ss); \
if (err) \
	err->Set(code, std::move(ss)); \
} while (0)

#	define DF_LASTERR(err,msg) do{	\
	df::String ss; \
	ss << msg; \
if (err) \
	err->SetLastError(ss); \
	df::LastErr(ss); \
} while (0);

#else
#	define DF_LOG(msg) 
#	define DF_LASTERR(err,msg) do{	\
if (err) \
	err->SetLastError(df::String()<<msg); \
} while (0); 

#	define DF_ERRLOG(err,code,msg) do{	\
if (err) \
	err->Set(code, df::String() << msg); \
} while (0);

#endif

namespace df
{
	using namespace sdf;
	inline bool WriteLog(const df::CC & msg, bool backTrace = true, const df::CC & file = tcc_("errorLog.txt"));
	inline bool LastErr(const df::CC & msg, const df::CC & file = tcc_("errorLog.txt"));
}

#endif // ErrLog_h__2013_7_30__16_30
